<?php

namespace app\index\controller;

use app\admin\model\TieComments;
use app\common\controller\Frontend;
use app\admin\model\Tie;
use app\common\model\Category;

class Index extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = 'default';

    public function index()
    {
        $where = [];
        if (input('category_id') != null)
            $where['category_id'] = input('category_id');
        $where['is_show_switch'] = 1;
        $tie = Tie::with(['user'])->where($where)
            ->select();

        foreach ($tie as $item){
            $item['category'] = Category::get(['id' => $item['category_id']]);
            $item['tie_num'] = TieComments::where(['user_id' => $this->auth->id])->count();
        }
        $this->assign(array(
            'title' => '主页',
            'tie' => $tie,
            'category' => Category::all(['type' => 'tie'])
        ));
        return $this->view->fetch();
    }

}
